package checkers.gui.panels;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.KeyEvent;
import java.util.Observer;
import java.util.ResourceBundle;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;

/**
 * Class LateralPanel
 * Implements Lateral Information Panel
 * used in the main view of this application
 * 
 * Display Game Information, type, time, player
 * data, name, pieces, coloros, and chat panel
 * 
 * @author Cristian Tardivo
 */
public class LateralPanel extends javax.swing.JPanel {
    private static final ResourceBundle lang = ResourceBundle.getBundle("checkers/common/lang");
    
    private final JPanel noWrapPanel;
    public final JTextPane chatPanel;
    private Observer observer;


    /**
     * Create Lateral Panel
     */
    public LateralPanel(){
        initComponents();
        // Create Chat Panel
        chatPanel = new javax.swing.JTextPane();
        chatPanel.setEditable(false);
        chatPanel.setBorder(null);
        chatPanel.setFocusable(false);
        // Chat Text Styles
        Style styleNormal = chatPanel.addStyle("Normal Style", null);
        StyleConstants.setForeground(styleNormal, Color.darkGray);
        StyleConstants.setBold(styleNormal, false);
        Style styleRed = chatPanel.addStyle("Red Player", styleNormal);
        StyleConstants.setForeground(styleRed, Color.red);
        StyleConstants.setBold(styleRed, true);
        Style styleBlack = chatPanel.addStyle("Black Player", styleNormal);
        StyleConstants.setForeground(styleBlack, Color.black);
        StyleConstants.setBold(styleBlack, true);
        noWrapPanel = new JPanel(new BorderLayout());
        noWrapPanel.add(chatPanel);
        jScrollPane1.setViewportView(noWrapPanel);
        //
        send_butt.setEnabled(false);
        chatMensaje.setEnabled(false);
        chatMensaje.setEditable(false);
        chatPanel.setEnabled(false);
    }
    
    /**
     * Add observer to this view
     * @param obs 
     */
    public synchronized void addObserver(Observer obs) {
        observer = obs;
    }
            
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        name_lbl2 = new javax.swing.JLabel();
        pieces_lbl2 = new javax.swing.JLabel();
        player2_pieces = new javax.swing.JLabel();
        player2_color = new javax.swing.JLabel();
        player2_name = new javax.swing.JLabel();
        color_lbl2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        pieces_lbl = new javax.swing.JLabel();
        player1_color = new javax.swing.JLabel();
        name_lbl = new javax.swing.JLabel();
        color_lbl = new javax.swing.JLabel();
        player1_name = new javax.swing.JLabel();
        player1_pieces = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        game_mode = new javax.swing.JLabel();
        mode_lbl = new javax.swing.JLabel();
        game_time = new javax.swing.JLabel();
        time_lbl = new javax.swing.JLabel();
        turn_lbl = new javax.swing.JLabel();
        turno = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        chatMensaje = new javax.swing.JTextField();
        send_butt = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();

        setPreferredSize(new java.awt.Dimension(215, 500));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(lang.getString("PLAYER_2"))); // NOI18N

        name_lbl2.setText(lang.getString("NAME")); // NOI18N

        pieces_lbl2.setText(lang.getString("PIECES")); // NOI18N

        color_lbl2.setText(lang.getString("COLOR")); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(color_lbl2)
                    .addComponent(name_lbl2)
                    .addComponent(pieces_lbl2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(player2_name)
                    .addComponent(player2_color)
                    .addComponent(player2_pieces))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(name_lbl2)
                    .addComponent(player2_name))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(color_lbl2)
                    .addComponent(player2_color))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(pieces_lbl2)
                    .addComponent(player2_pieces)))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(lang.getString("PLAYER_1"))); // NOI18N

        pieces_lbl.setText(lang.getString("PIECES")); // NOI18N

        name_lbl.setText(lang.getString("NAME")); // NOI18N

        color_lbl.setText(lang.getString("COLOR")); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(pieces_lbl)
                    .addComponent(color_lbl)
                    .addComponent(name_lbl))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(player1_name)
                    .addComponent(player1_color)
                    .addComponent(player1_pieces))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(name_lbl)
                    .addComponent(player1_name))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(color_lbl)
                    .addComponent(player1_color))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(pieces_lbl)
                    .addComponent(player1_pieces)))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(lang.getString("GAME"))); // NOI18N

        mode_lbl.setText(lang.getString("MODE")); // NOI18N

        game_time.setText("00:00:00");

        time_lbl.setText(lang.getString("TIME")); // NOI18N

        turn_lbl.setText(lang.getString("TURN")); // NOI18N

        turno.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        turno.setForeground(new java.awt.Color(255, 0, 51));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(time_lbl)
                    .addComponent(turn_lbl)
                    .addComponent(mode_lbl))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(game_mode)
                    .addComponent(turno)
                    .addComponent(game_time))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(time_lbl)
                    .addComponent(game_time))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(mode_lbl)
                    .addComponent(game_mode))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(turn_lbl)
                    .addComponent(turno)))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Chat"));

        chatMensaje.setToolTipText(lang.getString("MESSAGE")); // NOI18N
        chatMensaje.setEnabled(false);
        chatMensaje.setPreferredSize(new java.awt.Dimension(182, 20));
        chatMensaje.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                chatMensajeKeyPressed(evt);
            }
        });

        send_butt.setText(lang.getString("SEND")); // NOI18N
        send_butt.setEnabled(false);
        send_butt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                send_buttActionPerformed(evt);
            }
        });

        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setAutoscrolls(true);
        jScrollPane1.setEnabled(false);
        jScrollPane1.setPreferredSize(new java.awt.Dimension(182, 16));

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(send_butt))
            .addComponent(chatMensaje, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 152, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(chatMensaje, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(send_butt))
        );

        send_butt.getAccessibleContext().setAccessibleDescription(lang.getString("SEND_CURRENT_MESSAGE")); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(0, 11, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(5, 5, 5))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void chatMensajeKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_chatMensajeKeyPressed
        if(evt.getKeyCode() == KeyEvent.VK_ENTER){
            send_butt.doClick();
        }
    }//GEN-LAST:event_chatMensajeKeyPressed

    private void send_buttActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_send_buttActionPerformed
        observer.update(null, "SEND_CHAT_MESSAGE");
    }//GEN-LAST:event_send_buttActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JTextField chatMensaje;
    private javax.swing.JLabel color_lbl;
    private javax.swing.JLabel color_lbl2;
    public javax.swing.JLabel game_mode;
    public javax.swing.JLabel game_time;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel mode_lbl;
    private javax.swing.JLabel name_lbl;
    private javax.swing.JLabel name_lbl2;
    private javax.swing.JLabel pieces_lbl;
    private javax.swing.JLabel pieces_lbl2;
    public javax.swing.JLabel player1_color;
    public javax.swing.JLabel player1_name;
    public javax.swing.JLabel player1_pieces;
    public javax.swing.JLabel player2_color;
    public javax.swing.JLabel player2_name;
    public javax.swing.JLabel player2_pieces;
    public javax.swing.JButton send_butt;
    private javax.swing.JLabel time_lbl;
    private javax.swing.JLabel turn_lbl;
    public javax.swing.JLabel turno;
    // End of variables declaration//GEN-END:variables
}
